package com.jushu.storbox.callback;

import java.util.Comparator;

import com.jushu.storbox.constant.UiConstant;
import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.entities.FileType;

public class FileFolderInfoFileSizeSort implements Comparator<FileFolderInfo> {
	private int sortType ;
	private long diff ;
	public FileFolderInfoFileSizeSort(int sortType) {
		this.sortType = sortType;
	}

	@Override
	public int compare(FileFolderInfo lhs, FileFolderInfo rhs) {
		// TODO Auto-generated method stub
		if (lhs.getIsFile() == FileType.FOLDER_TYPE_VALUE && rhs.getIsFile() == FileType.FILE_TYPE_VALUE)
			return -1;
		if (lhs.getIsFile() == FileType.FILE_TYPE_VALUE && rhs.getIsFile() == FileType.FOLDER_TYPE_VALUE)
			return 1;
		diff = lhs.getSize() - rhs.getSize();
		//升序
		if (UiConstant.SORT_BY_SIZE == sortType) {
			if (diff > 0)
				return -1;
			else if (diff == 0)
				return 0;
			else
				return 1;
		} else {
			if (diff > 0)
				return 1;
			else if (diff == 0)
				return 0;
			else
				return -1;
		}

	}

}
